home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / Thread Manager Extension 2.0.1 / Sample Applications / Power Examples / SortPicts / Source / Menus.cp < prev    next >
Encoding:
Text File  |  1994-06-03  |  4.5 KB  |  174 lines  |  [TEXT/MPS ]

  1. /*************************************************************************************
  2.  *
  3.  *    Object Oriented Shell
  4.  *
  5.  *    Menus.cp - C Source File
  6.  *
  7.  *      Copyright © Apple Computer, Inc. 1988 - 1993
  8.  *      All rights reserved.
  9.  *
  10.  *    This file contains the code which handles the user selecting a menu item.
  11.  *    This code will automatically support the AppleMenuItems as well as call
  12.  *    a WindowObj of yours called "AboutObj" -- which is a kind of WindowObj in which
  13.  *    it's oversimplified to handle your about box.
  14.  *
  15.  *************************************************************************************/
  16.  
  17. #include "main.h"
  18. #include <Traps.h>
  19. #include "WindowObj.Link"
  20.  
  21. /**************************************************************************************
  22.  
  23.     AdjustMenus
  24.     
  25.     Enable and disable menus based on the current state.  The user can only
  26.     select enabled menu itmes.  We set up all the menuitems before calling
  27.     MenuSelect or MenuKey, since these are the only times that menu item can
  28.     be selected.  Note that MenuSelect is also the only time the user will see
  29.     menu itmes.  This approach to deciding what enable/disable state a menu
  30.     item has has the advantage of concentrating all the decisionmaking in one 
  31.     routine, as opposed to being spread throughout the application.  Other
  32.     application designs may take a different approach that is just as valid.
  33.     
  34. ***************************************************************************************/
  35. void    AppAdjustMenus()
  36. {
  37.     WindowPtr    window;
  38.     MenuHandle    menu;
  39.     
  40.     window = FrontWindow();
  41.     
  42.     menu = GetMHandle(mFile);
  43.     if( menu)
  44.     {
  45.         if( window != NIL)
  46.         {
  47.             EnableItem(menu, iNew);                // Enable the items, one at a time...
  48.             EnableItem(menu, iOpen);
  49.             EnableItem(menu, iClose);
  50.             DisableItem(menu, iSave);
  51.             DisableItem(menu, iSaveAs);
  52.             DisableItem(menu, iRevert);
  53.             DisableItem(menu, iPageSetup);
  54.             DisableItem(menu, iPrint);
  55.         }
  56.         else
  57.         {
  58.             EnableItem(menu, iNew);                // Enable the items, one at a time...
  59.             EnableItem(menu, iOpen);
  60.             DisableItem(menu, iClose);
  61.             DisableItem(menu, iSave);
  62.             DisableItem(menu, iSaveAs);
  63.             DisableItem(menu, iRevert);
  64.             DisableItem(menu, iPageSetup);
  65.             DisableItem(menu, iPrint);
  66.         }
  67.     
  68.         EnableItem(menu, iQuit);
  69.     }
  70.     
  71.     menu = GetMHandle( mEdit);
  72.     if( menu)
  73.     {
  74.         if( IsDAWindow(window))
  75.         {
  76.             EnableItem(menu, iUndo);
  77.             EnableItem(menu, iCut);
  78.             EnableItem(menu, iCopy);
  79.             EnableItem(menu, iClear);
  80.             EnableItem(menu, iPaste);
  81.         }
  82.         else
  83.         {
  84.             DisableItem(menu, iUndo);
  85.             DisableItem(menu, iCut);
  86.             DisableItem(menu, iCopy);
  87.             DisableItem(menu, iClear);
  88.             DisableItem(menu, iPaste);
  89.         }
  90.     }
  91. }
  92.  
  93. /**************************************************************************************
  94.  
  95.     AppMenu
  96.     
  97.     This is called when an item is chosen from the menu bar (after calling
  98.     MenuSelect or MenuKey).  It performs the right operation for each command.
  99.     It is good have both the result of MenuSelect and MenuKey go to one
  100.     routine like this to keep everything organized.
  101.     
  102. ***************************************************************************************/
  103. void    AppMenu(short menu, short item)
  104. {
  105.     Str255        daName;
  106.     WINDOWOBJ  *a;
  107.     
  108.     switch( menu )
  109.     {
  110.         case mApple:
  111.             switch( item)
  112.             {
  113.                 case iAbout:
  114.                     (void) Alert(rAboutAlert, NIL);
  115.                 default:
  116.                     GetItem(GetMHandle(mApple), item, daName);
  117.                     (void) OpenDeskAcc(daName);
  118.                     break;
  119.             }
  120.             break;
  121.  
  122.         case mFile:
  123.             switch( item)
  124.             {
  125.                 case iNew:
  126.                     a = new WINDOWOBJ;
  127.                     if( a->NewWindowObj() == false)
  128.                         delete a;                    
  129.                     break;
  130.                 case iClose:
  131.                     CloseAnyWindow(FrontWindow());
  132.                     break;
  133.                 case iQuit:
  134.                     gQuit = true;            // At first it's true, we're quitting...
  135.                     gQuit = CloseAllAppWindows( ) ? false : true;    
  136.                                             // This will tell us if the
  137.                                             // user selected CANCEL for any window.
  138.                                             // If the user selected CANCEL, a true
  139.                                             // will be returned to gQuit; However,
  140.                                             // gQuit needs to be true only if
  141.                                             // no windows were CANCELled.
  142.                     break;
  143.             }
  144.             break;
  145.             
  146.         case mEdit:
  147.             switch( item)
  148.             {
  149.                 /*  Call SystemEdit for DA editing & multifinder */
  150.                 /* since we personally don't do any editing */
  151.                 case iUndo:
  152.                 case iCut:
  153.                 case iCopy:
  154.                 case iPaste:
  155.                 case iClear:
  156.                     (void) SystemEdit(item-1);
  157.                     break;
  158.             }
  159.             break;
  160.         case 132:
  161.             a = new WINDOWOBJ;
  162.             if( a)
  163.             {
  164.                 MenuHandle    gPicturesMenu = GetMHandle( 132);
  165.                 
  166.                 GetItem( gPicturesMenu, item, a->pictureName);
  167.                 if( a->NewWindowObj() == false)
  168.                     delete a;
  169.             }
  170.             break;
  171.     }
  172.     HiliteMenu(0);
  173. }
  174.